package com.bishe.cyh.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bishe.cyh.mapper.TaskstopMapper;
import com.bishe.cyh.mode.*;
import com.bishe.cyh.service.TaskCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
@Service
public class TaskCatServiceImpl implements TaskCatService {

    private TaskstopMapper taskstopMapper;

    @Autowired
    public void setTaskstopMapper(TaskstopMapper taskstopMapper){
        this.taskstopMapper=taskstopMapper;
    }

    @Override
    public Result CatData(String id) {
        Datajirguo datajirguo = Get(id);
        Datav datav = new Datav();
        List<Pie> listmale = new ArrayList<>();
        Pie pie = new Pie();
        pie.setName("未知");
        pie.setValue(datajirguo.getUnknown());
        listmale.add(pie);
        Pie pie1 = new Pie();
        pie1.setName("男");
        pie1.setValue(datajirguo.getMale());
        listmale.add(pie1);
        Pie pie2 = new Pie();
        pie2.setName("女");
        pie2.setValue(datajirguo.getFemale());
        listmale.add(pie2);
        datav.setMale(listmale);
        List<Pie> listnn = new ArrayList<>();
        Pie pie3 = new Pie();
        pie3.setName("成功");
        pie3.setValue(datajirguo.getNn());
        listnn.add(pie3);
        Pie pie4 = new Pie();
        pie4.setName("失败");
        pie4.setValue(datajirguo.getImagecount()-datajirguo.getNn());
        listnn.add(pie4);
        datav.setNN(listnn);
        List<Pie>listRE = new ArrayList<>();
        Pie pie5 = new Pie();
        pie5.setName("成功");
        pie5.setValue(datajirguo.getUnknown()+datajirguo.getFemale()+datajirguo.getMale());
        listRE.add(pie5);
        Pie pie6 = new Pie();
        pie6.setName("失败");
        pie6.setValue(datajirguo.getImagecount()-(datajirguo.getUnknown()+datajirguo.getFemale()+datajirguo.getMale()));
        listRE.add(pie6);
        datav.setRe(listRE);
        List<Integer> agelist = new ArrayList<>();
        agelist.add(datajirguo.getRdd4());
        agelist.add(datajirguo.getRdd10());
        agelist.add(datajirguo.getRdd20());
        agelist.add(datajirguo.getRdd30());
        agelist.add(datajirguo.getRdd40());
        agelist.add(datajirguo.getRdd50());
        agelist.add(datajirguo.getRdd60());
        agelist.add(datajirguo.getRdd70());
        agelist.add(datajirguo.getRdd80());
        agelist.add(datajirguo.getRdd81());
        datav.setAge(agelist);
        return new Result(0,"成功",datav);
    }

    @Override
    public Result ifData(String id) {
        Datajirguo datajirguo = Get(id);
        if (datajirguo==null){
            return new Result<Messqge>(-1,"失败",new Messqge("删除失败"));
        }
        return new Result<Messqge>(0,"成功",new Messqge("处在该数据结果"));
    }

    public Datajirguo Get(String id){

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("id",id);
        Datajirguo datajirguo = taskstopMapper.selectOne(queryWrapper);
        return datajirguo;
    }
}
